<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<a href="weixin://" class="btn-download">立即打开</a>
　　
</body>
<script>
    // 为btn-download 绑定事件，如果在500ms内，没有解析到协议，那么就会跳转到下载链接
    var appstore, ua = navigator.userAgent;
    if(ua.match(/Android/i)){
        appstore = 'http://app.mi.com/details?id=com.lcjt.lvyou&ref=search';
    }
    if(ua.match(/iphone|ipod|ipad/)){
        appstore = "https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8&ign-mpt=uo%3D4";
    }
    function applink(fail){
        return function(){
            var clickedAt = +new Date;
// During tests on 3g/3gs this timeout fires immediately if less than 500ms.
            setTimeout(function(){
// To avoid failing on return to MobileSafari, ensure freshness!
                if (+new Date - clickedAt < 2000){
                    window.location = fail;
                }
            }, 500);
        };
    }
    $('.icon-download, .btn-download')[0].onclick = applink(appstore);
</script>
</html>